package icu.sehnen.qiniu.controller;
import com.qiniu.util.Auth;
import icu.sehnen.common.result.CommonResult;
import icu.sehnen.qiniu.entity.Qiniu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class GetImageToken {
    @Autowired
    Qiniu qiniu;
    @RequestMapping("/getToken")
    public CommonResult getToken(){
        HashMap<String, String> res = new HashMap<>();
        Auth auth = Auth.create(qiniu.getAccessKey(), qiniu.getSecretKey());
        String upToken = auth.uploadToken(qiniu.getBucket());
        res.put("upToken",upToken);
        res.put("host",qiniu.getHost());
        return CommonResult.success(res);
    }
}
